using System;

using System.Xml;
using System.Diagnostics;
using System.IO;

using CUtil;
using CGraph;
using CStock;

namespace CStock
{
	public class Dates : StockObjectBase, IDates
	{
		private static DateTime DefaultStartDate = new DateTime(1950,01,01);
		private static DateTime DefaultEndDate = DateTime.Now;

		private DateTime dateMaxReset;
		private DateTime dateMinReset;

		private DateTime dateMinChartCurrent;
		private DateTime dateMaxChartCurrent ;

		private DateTime dateMinChart;
		private DateTime dateMaxChart;

		private DateTime dateIntraday;

		private DateTime dateMinUserTrade;
		private DateTime dateMaxUserTrade ;
	
		/// <summary>
		/// dateStart
		/// </summary>
		private DatePeriods datePeriods;
		private DateTime dateMinSimulation;
		private DateTime dateMaxSimulation;
		private DateTime dateMaxAvailable;//{get;set;}
		private DateTime dateMinAvailable;//{get;set;}
        private DateTime dateMinWebupdate;
        private DateTime dateMaxWebupdate;

        //DateTime DateMinWebupdate { get; set; }
        //DateTime DateMaxWebupdate { get; set; }


		public Dates()
		{
			Defaults();
		}
		public void Defaults()
		{
			datePeriods = CUtil.DatePeriods.Period2J;
			//System.Windows.Forms.MessageBox.Show("No valid date - setting default");
			//			this.dateMinSimulation = DateTime.MinValue;
			//			this.dateMaxAvailable = DateTime.Now;
			this.dateMinReset = DefaultStartDate;
			this.dateMaxReset = DefaultEndDate;


			this.dateMinSimulation = this.dateMinReset;
			this.dateMaxSimulation = this.dateMaxReset;
	

			this.dateMinAvailable = this.dateMinReset;
			this.dateMaxAvailable= this.dateMaxReset;

			this.dateMinUserTrade = this.dateMinReset;
			this.dateMaxUserTrade  = this.dateMaxReset;

			this.dateMinChartCurrent = this.dateMinReset;
			this.dateMaxChartCurrent = this.dateMaxReset;

			this.dateMinChart = this.dateMinReset;
			this.dateMaxChart = this.dateMaxReset;

			this.dateIntraday = DateTime.Now;
            dateMaxWebupdate = DateTime.Now;
            //dateMinWebupdate = dateMaxWebupdate.AddDays(-200);
            dateMinWebupdate = new DateTime(2000, 1, 1);//





		}
			

		#region dates

		/// <summary>
		/// DateEnd
		/// </summary>
		[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DatePeriods DatePeriods 
		{
			get
			{
				return this.datePeriods;
			}
			set
			{
				this.datePeriods = value;
			}
		}
		/// <summary>
		/// DateEnd
		/// </summary>
		[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMin
		{
			get
			{
				return this.dateMinChartCurrent;


			}
		}
		/// <summary>
		/// DateStart
		/// </summary>
		[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMax
		{
			get
			{
				return this.dateMaxChartCurrent;
//				switch(this.programMode)
//				{
//					case(ProgramModes.Chart):
//					{
//						//return this.dateMaxAvailable;
//						return this.dateMaxChartCurrent;
//
//					}
//					case(ProgramModes.Simulation):
//					{
//						return this.dateMaxSimulation;
//					}
//					case(ProgramModes.UserTrade):
//					{
//						return this.DateMaxUserTrade;
//					}
//					default:
//					{
//						return this.dateMaxAvailable;
//					}
//
//				}
			}
		}
        // [System.Xml.Serialization.XmlIgnoreAttribute()]
        public DateTime DateMinWebupdate
        {
            get
            {
                return this.dateMinWebupdate;
            }
            set
            {
                this.dateMinWebupdate = value;
            }
        }
        // [System.Xml.Serialization.XmlIgnoreAttribute()]
        public DateTime DateMaxWebupdate
        {
            get
            {
                return this.dateMaxWebupdate;
            }
            set
            {
                this.dateMaxWebupdate = value;
            }
        }
	
		/// <summary>
		/// DateEnd
		/// </summary>
		[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMinReset
		{
			get
			{
				return this.dateMinReset;
			}
		}
		public DateTime DateMaxReset
		{
			get
			{
				return this.dateMaxReset;
			}
		}
	
		/// <summary>
		/// DateEnd
		/// </summary>
		public DateTime DateMinChart
		{
			get
			{
				return this.dateMinChart;
				
			}
			set
			{
				DateTime oldVal = this.dateMinChart;
				this.dateMinChart = value;
				this.dateMinChartCurrent = value;

				this.dateMinChartCurrent = value;
				if(dateMinChart < this.dateMinReset)
					this.dateMinChart = this.dateMinReset;
				this.RaiseObjectChangedEvent(this,"DateMinChart",oldVal ,value);
				
				//this.dateMinChartCurrent = value;
			}
		}
		/// <summary>
		/// DateEnd
		/// </summary>
		public DateTime DateMaxChart
		{
			get
			{
				return this.dateMaxChart;
				
			}
			set
			{
				DateTime oldVal = this.dateMaxChart;
				this.dateMaxChart = value;
				this.dateMaxChartCurrent = value;

				if(dateMaxChart > this.dateMaxReset)
					this.dateMaxChart = this.dateMaxReset;
				this.RaiseObjectChangedEvent(this,"DateMaxChart",oldVal ,value);

				//this.dateMinChartCurrent = value;
			}
		}


		/// <summary>
		/// DateEnd
		/// </summary>
		[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMinChartCurrent
		{
			get
			{
				return this.dateMinChartCurrent;
				
			}
			set
			{
				DateTime oldVal = this.dateMinChartCurrent;
				this.dateMinChartCurrent = value;
				if(dateMinChartCurrent < this.dateMinReset)
					this.dateMinChartCurrent = this.dateMinReset;
				this.RaiseObjectChangedEvent(this,"DateMinChartCurrent",oldVal ,value);

				//this.dateMinChartCurrent = value;
			}
		}
		/// <summary>
		/// DateEnd
		/// </summary>
		[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMinChartCurrentSilent
		{
			get
			{
				return this.dateMinChartCurrent;
				
			}
			set
			{
				this.dateMinChartCurrent = value;
				
			}
		}
		/// <summary>
		/// DateEnd
		/// </summary>
		[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMinChartSilent
		{
			get
			{
				return this.dateMinChart;
				
			}
			set
			{
				this.dateMinChart = value;
				this.dateMinChartCurrent = value;

			}
		}
		/// <summary>
		/// DateEnd
		/// </summary>
		[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMaxChartCurrent
		{
			get
			{
				return this.dateMaxChartCurrent;
				//				switch(this.programMode)
				//				{
				//					case(ProgramModes.Chart):
				//					{
				//						return this.dateMaxChartCurrent;
				//					}
				//					case(ProgramModes.Simulation):
				//					{
				//						return this.dateMaxSimulation;
				//					}
				//					case(ProgramModes.UserTrade):
				//					{
				//						return this.dateMaxUserTrade;
				//					}
				//					default:
				//					{
				//						return this.dateMaxAvailable;
				//					}
				//
				//				}
			}
			set
			{
				DateTime oldVal = this.dateMaxChartCurrent ;
				this.dateMaxChartCurrent = value;
				if(dateMaxChartCurrent > this.dateMaxReset)
					this.dateMaxChartCurrent = this.dateMaxReset;
				if(dateMaxChartCurrent < this.dateMinReset)
					this.dateMaxChartCurrent = this.dateMinReset;

				this.RaiseObjectChangedEvent(this,"DateMaxChartCurrent",oldVal ,value);

			}
		}
		/// <summary>
		/// DateEnd
		/// </summary>
		//[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMinUserTrade
		{
			get
			{
				return this.dateMinUserTrade;
			}
			set
			{
				DateTime oldVal = this.dateMinUserTrade ;
				this.dateMinUserTrade = value;
				if(dateMinUserTrade < this.dateMinReset)
					this.dateMinUserTrade = this.dateMinReset;
				this.RaiseObjectChangedEvent(this,"DateMinUserTrade",oldVal ,value);
			}
		}
		//[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMaxUserTrade
		{
			get
			{
				return this.dateMaxUserTrade;
			}
			set
			{
				DateTime oldVal = this.dateMaxUserTrade ;
				this.dateMaxUserTrade = value;
				if(dateMaxUserTrade > this.dateMaxReset)
					this.dateMaxUserTrade = this.dateMaxReset;
				if(dateMaxUserTrade < this.dateMinReset)
					this.dateMaxUserTrade = this.dateMinReset;

				this.RaiseObjectChangedEvent(this,"DateMaxUserTrade",oldVal ,value);

				
			}
		}
		/// <summary>
		/// DateEnd
		/// </summary>
		//[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMaxSimulation
		{
			get
			{
				return this.dateMaxSimulation;
				//return this.dateMaxAvailable;
			}
			set
			{
				this.dateMaxSimulation = value;
				//				DateTime oldVal = dateMaxAvailable;
				//				this.dateMaxAvailable = value;
				//				if(dateMaxAvailable > this.dateMaxReset)
				//					this.dateMaxAvailable = this.dateMaxReset;
				//				if(dateMaxAvailable < this.dateMinReset)
				//					this.dateMaxAvailable = this.dateMinReset;
				//
				//
				//				this.RaiseObjectChangedEvent(this,"DateMaxSimulation",oldVal,value);
				
			}
		}

		/// <summary>
		/// DateStart
		/// </summary>
		//[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMinSimulation
		{
			get
			{
				//return this.dateMinSimulation;
				return this.dateMinSimulation;
			}
			set
			{
				this.dateMinSimulation = value;
				//				DateTime oldVal = this.dateMinSimulation;
				//				this.dateMinSimulation = value;
				//				if(dateMinSimulation < this.dateMinReset)
				//					this.dateMinSimulation = this.dateMinReset;
				//
				//				this.RaiseObjectChangedEvent(this,"DateMinSimulation",this.dateMinSimulation,value);
				
			}
		}
		/// <summary>
		/// DateStart
		/// </summary>
		//[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateIntraday
		{
			get
			{
				
				return this.dateIntraday;
			}
			set
			{
				this.dateIntraday = value;
			
			}
		}
		[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMaxAvailable
		{
			//			get
			//			{
			//				//return this.dateMinSimulation;
			//				return this.dateMaxAvailable;
			//			}
			set
			{
				this.dateMaxAvailable = value;
			}
		}
		[System.Xml.Serialization.XmlIgnoreAttribute()]
		public DateTime DateMinAvailable
		{
			//			get
			//			{
			//				//return this.dateMinSimulation;
			//				return this.dateMaxAvailable;
			//			}
			set
			{
				this.dateMinAvailable = value;
			}
		}


		#endregion

	}
}
